package com.zhouwr.common.device.vo;

import com.alibaba.fastjson.JSONObject;
import com.zhouwr.common.enums.ReportMode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @description: 上报数据
 * @author: zhouwr
 * @create: 2020-11-24 10:06
 * @version：1.0
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReportDataVo {
    private Object code;
    private Object value;
    private Date reportTime;
    private ReportMode inputMode;

    public ReportDataVo(String data, ReportMode inputMode, Date reportTime) {
        this.inputMode = inputMode;
        this.reportTime = reportTime;

        if (StringUtils.isNotBlank(data)) {
            JSONObject.parseObject(data).forEach((key, value1) -> {
                this.value = value1;
                this.code = key;
            });
        }
    }
}
